def prime(e):
    f = True
    for y in range(2, int (e ** 0.5)+1):
        if e % y == 0:
            f = False
            break
    return f

n  = int(input())
if n < 1000 or n > 9999:
    print(0)
else:
    dgts = str(n)
    mx = 0
    for i in range(len(dgts)):
        for j in range(i+1, len(dgts)+1):
            num = int(dgts[i:j])
            if prime(num):
                mx = max(mx, num)
    print(mx)
